package com.cssw.fyzb.wap.service;

import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.wap.model.vo.*;
import com.ydn.appserver.MinaAppClient;
import com.ydn.appserver.Request;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author Feng Chen
 */
@Service
public class VedioService extends BaseService {

    @Autowired
    private MinaAppClient busiClient;

    public AjaxData<AddVideoVo> addVedio(Long userId, String title, String href, String thumb, String vodId, String draft, String lat, String lng) {
        Request request = new Request("AddVideo");
        request.setParameter("userId", userId);
        request.setParameter("title", title);
        request.setParameter("href", href);
        request.setParameter("thumb", thumb);
        request.setParameter("vodId", vodId);
        request.setParameter("draft", draft == null ? "0" : draft);
        request.setParameter("lat", lat);
        request.setParameter("lng", lng);
        return convertData(busiClient.send(request), AddVideoVo.class);
    }

    public AjaxPage<VideoVo> listVedio(Long userId, String audit, int pageNumber, int pageSize) {
        Request request = new Request("ListVideo");
        request.setParameter("userId", userId);
        if (StringUtils.isNotEmpty(audit)) {
            request.setParameter("audit", audit);
        }
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), VideoVo.class);
    }

    public AjaxPage<FocusVideoVo> listFocus(Long userId, int pageNumber, int pageSize) {
        Request request = new Request("ListFocusVideo");
        request.setParameter("userId", userId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), FocusVideoVo.class);
    }

    public AjaxPage<ScityVideoVo> listScity(Long userId, String lat, String lng, int pageNumber, int pageSize) {
        Request request = new Request("ListScityVideo");
        request.setParameter("userId", userId);
        request.setParameter("lat", lat);
        request.setParameter("lng", lng);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), ScityVideoVo.class);
    }

    public AjaxPage<FoundVideoVo> listFound(Long userId, int pageNumber, int pageSize) {
        Request request = new Request("ListFoundVideo");
        request.setParameter("userId", userId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), FoundVideoVo.class);
    }

    public AjaxPage<FoundVideoByPhpVo> listFoundByPhp(int pageNumber, int pageSize) {
        Request request = new Request("ListFoundByPhpVideo");
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), FoundVideoByPhpVo.class);
    }

    public AjaxPage<FocusVideoByPhpVo> listFocusByPhp(Long userId, int pageNumber, int pageSize) {
        Request request = new Request("ListFocusByPhpVideo");
        request.setParameter("userId", userId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), FocusVideoByPhpVo.class);
    }

    public AjaxPage<ScityVideoByPhpVo> listScityByPhp(String city, String lat, String lng, int pageNumber, int pageSize) {
        Request request = new Request("ListScityByPhpVideo");
        request.setParameter("city", city);
        request.setParameter("lat", lat);
        request.setParameter("lng", lng);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), ScityVideoByPhpVo.class);
    }

    public AjaxPage<HotVideoVo> listHot(Long userId, int pageNumber, int pageSize) {
        Request request = new Request("ListHotVideo");
        request.setParameter("userId", userId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), HotVideoVo.class);
    }

    public AjaxData<VideoStatVo> getStat(Long videoId, Long userId) {
        Request request = new Request("GetVideoStat");
        request.setParameter("videoId", videoId);
        request.setParameter("userId", userId);

        return convertData(busiClient.send(request), VideoStatVo.class);
    }

    public AjaxData like(Long userId, Long videoId) {
        Request request = new Request("LikeVideo");
        request.setParameter("userId", userId);
        request.setParameter("videoId", videoId);
        request.setParameter("type", "1");
        return convertData(busiClient.send(request));
    }

    public AjaxData cancelLike(Long userId, Long videoId) {
        Request request = new Request("LikeVideo");
        request.setParameter("userId", userId);
        request.setParameter("videoId", videoId);
        request.setParameter("type", "0");
        return convertData(busiClient.send(request));
    }

    public AjaxData download(Long userId, Long videoId) {
        Request request = new Request("DownloadVideo");
        request.setParameter("userId", userId);
        request.setParameter("videoId", videoId);
        return convertData(busiClient.send(request));
    }

    public AjaxData report(Long userId, Long videoId) {
        Request request = new Request("ReportVideo");
        request.setParameter("userId", userId);
        request.setParameter("videoId", videoId);
        return convertData(busiClient.send(request));
    }

    public AjaxData viewTime(Long userId, Long videoId, Integer timeLong) {
        Request request = new Request("ViewTimeVideo");
        request.setParameter("userId", userId);
        request.setParameter("videoId", videoId);
        request.setParameter("timeLong", timeLong);
        return convertData(busiClient.send(request));
    }

    public AjaxPage<VideoHotDefVo> listVideoHotDef() {
        Request request = new Request("ListVideoHotDef");
        return convertPage(busiClient.send(request), VideoHotDefVo.class);
    }

    public AjaxData buyVideoHot(Long userId, Long hotId, Long videoId, String pwd) {
        Request request = new Request("BuyVideoHot");
        request.setParameter("userId", userId);
        request.setParameter("hotId", hotId);
        request.setParameter("videoId", videoId);
        request.setParameter("pwd", pwd);
        return convertData(busiClient.send(request));
    }

    public AjaxPage<LikeVideoVo> listVideoLike(Long userId, int pageNumber, int pageSize) {
        Request request = new Request("ListVideoLike");
        request.setParameter("userId", userId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), LikeVideoVo.class);
    }

    public AjaxPage<VideoCommentVo> listComment(Long videoId, int pageNumber, int pageSize) {
        Request request = new Request("ListVideoComment");
        request.setParameter("videoId", videoId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), VideoCommentVo.class);
    }

    public AjaxPage<VideoCommentVo> listCommentReply(Long commentId, int pageNumber, int pageSize) {
        Request request = new Request("ListVideoCommentReply");
        request.setParameter("commentId", commentId);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), VideoCommentVo.class);
    }

    public AjaxData likeComment(Long userId, Long commentId) {
        Request request = new Request("LikeVideoComment");
        request.setParameter("userId", userId);
        request.setParameter("commentId", commentId);
        return convertData(busiClient.send(request));
    }

    public AjaxData<AddCommentVo> addComment(Long userId, String content, Long replyCommentId, Long videoId) {
        Request request = new Request("AddVideoComment");
        request.setParameter("userId", userId);
        request.setParameter("content", content);
        request.setParameter("videoId", videoId);
        request.setParameter("replyCommentId", replyCommentId);
        return convertData(busiClient.send(request), AddCommentVo.class);
    }

    public AjaxPage<SearchVideoVo> searchVideo(Long userId, String key, Integer pageNumber, Integer pageSize) {
        Request request = new Request("SearchVideo");
        request.setParameter("userId", userId);
        request.setParameter("key", key);
        request.setParameter("pageNumber", pageNumber);
        request.setParameter("pageSize", pageSize);
        return convertPage(busiClient.send(request), SearchVideoVo.class);
    }

    public AjaxData actionByPhp(Long videoId, String action, Integer num, String userId) {
        Request request = new Request("ActionByPhpVideo");
        request.setParameter("videoId", videoId);
        request.setParameter("action", action);
        request.setParameter("num", num);
        request.setParameter("userId", userId);
        return convertData(busiClient.send(request));
    }

    public AjaxData deleteByEs(Long id) {
        Request request = new Request("DeleteVideoEs");
        request.setParameter("id", id);
        return convertData(busiClient.send(request));
    }

    public AjaxData getAddVideoEs(Long id) {
        Request request = new Request("AddVideoEs");
        request.setParameter("id", id);
        return convertData(busiClient.send(request));
    }

    public AjaxData<VideoStatNumVo> getVideoStatNum(Long videoId) {
        Request request = new Request("GetVideoStatNum");
        request.setParameter("videoId", videoId);

        return convertData(busiClient.send(request), VideoStatNumVo.class);
    }
}
